#include<stdio.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include<stdlib.h>

int main()
{

    pid_t id = fork();

    if(id == 0)
    {
        //子进程
        printf("子进程替换前，pid：%d，ppid：%d\n",getpid(),getppid());
        
        execlp("ls","-a","-l");
        exit(11);
    }
    
    //父进程
    printf("我是父进程，pid : %d,ppid: %d\n",getpid(),getppid());
    int status = 0;
    pid_t ret = waitpid(-1,&status,0);
    if(ret == id)
    {

        if(WIFEXITED(status))
        {
            printf("exit code:  %d\n",WEXITSTATUS(status));
        }
    }
    else{
        printf("wait fail\n");

    }
    
    return 0;
}
